#include "logdlg.h"
#include <QDateTime>


LogDlg::LogDlg()
{
     setupUi(this);

     connect(clearBtn,SIGNAL(clicked()),this,SLOT(clearLogs()));
     connect(closeBtn,SIGNAL(clicked()),this,SLOT(close()));
}

void LogDlg::addLog(LogType type,LogLevel level,const QString &msg)
{
    QString text;

    QDateTime dt;
    QTime time;
    QDate date;
    dt.setTime(time.currentTime());
    dt.setDate(date.currentDate());
    QString currentDate = dt.toString("yyyy:MM:dd:hh:mm:ss");

    if(type==ONE)
    {
        text.append("one:>");
    }
    else if(type==FTP)
    {
        text.append("ftp:>");
    }
    text.append(currentDate);
    text.append("-");
    if(level==ERROR)
    {
        text.append("<font color=red>");
        text.append(msg);
        text.append("</font>");
    }
    else if(level==NORMAL)
    {
        text.append("<font color=blue>");
        text.append(msg);
        text.append("</font>");
    }
    else if(level==WARN)
    {
        text.append("<font color=black>");
        text.append(msg);
        text.append("</font>");
    }



    this->textEdit->append(text);
}

void LogDlg::clearLogs()
{
    this->textEdit->clear();
}

void LogDlg::Oper(const QString &msg)
{
    QString text;
    text.append("<font color='#008000'>");
    text.append("################################");
    text.append(msg);
    text.append("################################");
    text.append("</font>");

    this->textEdit->append(text);

}
